//
//  XMBaseMessageTableCell.m
//  XMMessageKit
//
//  Created by lishi on 2019/3/5.
//  Copyright © 2019 lishi. All rights reserved.
//

#import "XMBaseMessageTableCell.h"

//
#import "Masonry.h"

@interface XMBaseMessageTableCell ()

@end

@implementation XMBaseMessageTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        [self reloadDefultMeeageCell];
        [self reloadDefultMeeageKitCell];
    }
    return self;
}

//- (void)setUpValueForCellWithModel:(XMMessageModel *)model {
//    
//}

- (void)setUpValueForCellMessageWithModel:(XMMessageModel *)model {

}

- (void)reloadDefultMeeageKitCell {
    [self.contentView addSubview:self.messageHeadImageView];
    [self.messageHeadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(self.contentView).offset(15);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    
    [self.contentView addSubview:self.messageNameLabel];
    [self.messageNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.messageHeadImageView.mas_top).offset(0);
        make.left.mas_equalTo(self.messageHeadImageView.mas_right).offset(5);
        make.right.mas_equalTo(self.contentView).offset(-15);
        make.height.offset(25);
    }];
}

//- (void)reloadDefultMeeageCell {
//    [self.contentView addSubview:self.messageHeadImageView];
//    [self.messageHeadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.mas_equalTo(self.contentView).offset(15);
//        make.size.mas_equalTo(CGSizeMake(45, 45));
//    }];
//    
//    [self.contentView addSubview:self.messageNameLabel];
//    [self.messageNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.messageHeadImageView.mas_top).offset(0);
//        make.left.mas_equalTo(self.messageHeadImageView.mas_right).offset(5);
//        make.right.mas_equalTo(self.contentView).offset(-15);
//        make.height.offset(25);
//    }];
//}

- (UILabel *)messageNameLabel {
    if (!_messageNameLabel) {
        _messageNameLabel = [[UILabel alloc] init];
        _messageNameLabel.text = @"messageNameLabel";
        _messageNameLabel.backgroundColor = [UIColor yellowColor];
    }
    return _messageNameLabel;
}

- (UIImageView *)messageHeadImageView {
    if (!_messageHeadImageView) {
        _messageHeadImageView = [[UIImageView alloc] init];
        _messageHeadImageView.backgroundColor = [UIColor redColor];
    }
    return _messageHeadImageView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    // 获取 contentView 所有子控件
    NSArray<__kindof UIView *> *subViews = self.contentView.subviews;
    // 创建颜色数组
    NSMutableArray *colors = [NSMutableArray array];
    
    for (UIView *view in subViews) {
        // 获取所有子控件颜色
        [colors addObject:view.backgroundColor ?: [UIColor clearColor]];
    }
    // 调用super
    [super setSelected:selected animated:animated];
    // 修改控件颜色
    for (int i = 0; i < subViews.count; i++) {
        subViews[i].backgroundColor = colors[i];
    }
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    // 获取 contentView 所有子控件
    NSArray<__kindof UIView *> *subViews = self.contentView.subviews;
    // 创建颜色数组
    NSMutableArray *colors = [NSMutableArray array];
    
    for (UIView *view in subViews) {
        // 获取所有子控件颜色
        [colors addObject:view.backgroundColor ?: [UIColor clearColor]];
    }
    // 调用super
    [super setHighlighted:highlighted animated:animated];
    // 修改控件颜色
    for (int i = 0; i < subViews.count; i++) {
        subViews[i].backgroundColor = colors[i];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
@end
